#!/usr/bin/node

const EventEmitter=require('events').EventEmitter;



function Dog(name,energy){
  let _name=name,

      _energy=energy,
      that  =this;
  EventEmitter.call(this);
  let timer=setInterval(()=>{
    if(_energy>0){
      //绑定事件 on后面是响应事件zr
      that.emit('bark');
      _energy=_energy-1;
    }else{
      clearInterval(timer);
    }

  },1000);
  //返回私有属性的名字

  this.name=()=>_name;
  this.energy=()=>_energy;
}



Dog.prototype=EventEmitter.prototype;
module.exports=Dog;
